package projectchumashgeniusproject;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.List;
import projectchumashgeniusproject.ProjectChumashGeniusProject.BookName;

public class Chumash implements Serializable
{
    private Book[] books;
    
    public Chumash()
    {
        this.books = new Book[BookName.values().length];
        for(BookName bn: BookName.values())
            this.books[bn.ordinal()] = new Book(bn);
    }
    public Book[] getBooks()
    {
        List<Chapter> chapters;
        Book[] booksCopy = new Book[BookName.values().length];
        for(BookName bn: BookName.values())
                booksCopy[bn.ordinal()] = new Book(bn);
        
        for(int i = 0; i < booksCopy.length; i++)
        {
            chapters = books[i].getChapters();
            for(Chapter c: chapters)
                booksCopy[i].addChapter(c);
        }
        return booksCopy;
    }
    public void addChapter(Chapter c)
    {
        books[c.getBook().ordinal()].addChapter(c);
    }
    public void addVerse(Verse v)
    {
        books[v.getBook().ordinal()].addVerse(v);
    }
    public void deleteVerse(BookName bn, int cn, int vn)
    {
        books[bn.ordinal()].deleteVerse(cn, vn);
    }
    public void writeObject(ObjectOutputStream s) throws FileNotFoundException, IOException
    {
        s.writeObject(books);
    }
    public void readObject(ObjectInputStream s) throws FileNotFoundException, IOException, ClassNotFoundException
    {
        this.books = (Book[]) s.readObject();
    }
}